package com.atguigu.wuliupublisher.mapper;


import com.atguigu.wuliupublisher.bean.TradeOrgOrderDayBean;
import com.atguigu.wuliupublisher.bean.TrandsTruckStatisticsBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TrandsStatsMapper {

    @Select("select truck_model_id,truck_model_name,sum(mileage) mileage ,sum(ct) ct,cast(sum(td)/(1000*60*60*24) as decimal(16,2)) as td,cast(sum(td)/sum(ct)/(1000*60*60*24) as decimal(16,2)) as td_by_ct , sum(mileage)/sum(ct) mileage_by_ct " +
            " from dws_trands_truck_statistics partition (par#{date}) group by truck_model_id, truck_model_name")
    List<TrandsTruckStatisticsBean> selectTruckStatistics(@Param("date") Integer date);

    @Select("select org_name ,sum(order_amount_base) order_amount_base,sum(order_count_base) order_count_base from dws_trade_org_order_day_base " +
            " partition (par#{date}) group by org_name order by order_amount_base desc limit #{limit};")
    List<TradeOrgOrderDayBean> selectOrgOrderDayBase(@Param("date")Integer date, @Param("limit") Integer limit);

    @Select("select sum(order_amount_base) as amount from dws_trade_org_order_day_base partition (par#{date})")
    Double selectSumAmount(@Param("date") Integer date);
}
